﻿using System.Linq;
using System.Xml.Linq;

namespace _1_17
{
    class Program
    {
        static void Main_()
        {
            XDocument doc = XDocument.Load("../../../1-17-data.xml");
            var filltered = from p in doc.Descendants("Product")
                            join s in doc.Descendants("Supplier")
                                on (int)p.Attribute("SuppliderID")
                                equals (int)s.Attribute("SuppliderID")
                            where (decimal)p.Attribute("Price") > 10
                            orderby (string)s.Attribute("Name"),
                                    (string)p.Attribute("Name")
                            select new
                            {
                                SupplierName = (string)s.Attribute("Name"),
                                ProductName = (string)p.Attribute("Name")
                            };
            foreach (var v in filltered)
            {
                System.Console.WriteLine("Supplier={0}; Product={1}", v.SupplierName, v.ProductName);
            }
        }
    }
}
//Linq可以直接查询xml中的数据，就像数据库和SQL一样
//但这样会使得代码不那么直观了